package com.webapps.tvprogram.utils;

import java.util.Date;

public class DateParser {
    /**
     * 
     * @param date
     *            String date in format DD-MM-YYYY
     * @param timeOfADay
     *            String time in format HH:MM
     * @return Date representation of a given Strings (date and time)
     */
    public Date parseDate(String date, String timeOfADay) {
        String[] dateElemsStr = date.replace("\\n", "").split("-");
        String[] timeElemsStr = timeOfADay.substring(0, 5).split(":");
        // day, month, year
        int[] dateElems = { Integer.parseInt(dateElemsStr[0]), Integer.parseInt(dateElemsStr[1]),
                Integer.parseInt(dateElemsStr[2]) };
        // hour, minute
        int[] timeElems = { Integer.parseInt(timeElemsStr[0]), Integer.parseInt(timeElemsStr[1]) };

        Date returnDate = new Date(dateElems[2], dateElems[1], dateElems[0], timeElems[0], timeElems[1]);
        return returnDate;
    }

    /**
     * 
     * @param fullDate
     *            String date in format DD-MM-YYYY HH:MM
     * @return
     */
    public Date parseDate(String fullDate) {
        String[] dateElemsStr = fullDate.split(" ");
        return parseDate(dateElemsStr[0], dateElemsStr[1]);
    }
}
